home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvi2qms / qmsdev.c < prev    next >
C/C++ Source or Header  |  1990-10-01  |  4KB  |  146 lines

  1. /* qmsdev.c The qms output driver for dviqms program.
  2.  * Copyright 1985 Massachusetts Institute of Technology.
  3.  * Author: cjl@oz
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "dev.h"
  8.  
  9. #define DEV_DPI             300 /* Device dots per inch */
  10. #define DEV_XOFFSET        300
  11. #define DEV_YOFFSET        300
  12.  
  13. FILE *dev_out;
  14. long dev_h,dev_v;
  15. unsigned long dev_options;
  16. char dev_hex[] = "0123456789ABCDEF";
  17.  
  18. dev_setc(ch,xsize)
  19.      unsigned long ch;
  20.      int xsize;
  21. {
  22.   if (ch < '\040' || ch == '^' || ch == '\177') {
  23.     putc('^',dev_out);
  24.     putc('$',dev_out);
  25.     putc(dev_hex[(ch >> 4) & 017],dev_out);
  26.     putc(dev_hex[ch & 017],dev_out);
  27.   } else putc(ch,dev_out);
  28.   dev_h += xsize;
  29. }
  30.  
  31. dev_position(x,y)
  32.      long x,y;
  33. {
  34.   if (dev_h != x) fprintf(dev_out,"^IH%04.4d",(dev_h = x) + DEV_XOFFSET);
  35.   if (dev_v != y) fprintf(dev_out,"^IV%04.4d",(dev_v = y) + DEV_YOFFSET);
  36. }
  37.  
  38. dev_draw_box(h,w)
  39.      long h,w;
  40. {
  41.   fprintf(dev_out,"^JR-%04.4d^LS%04.4d%04.4d",h,w,h);
  42.   dev_v -= h;
  43.   dev_h += w;
  44. }
  45.  
  46. dev_eop()
  47. {
  48.   fprintf(dev_out,"^G^-\f");
  49.   fflush(dev_out);
  50.   fprintf(dev_out,"^IH%04.4d^IV%04.4d",DEV_XOFFSET,DEV_YOFFSET);
  51.   dev_h = dev_v = 0;
  52. }
  53.  
  54. #define QUIC_ON        "\r^PY^-\r"
  55. #define QUIC_OFF    "\r^-^PN^-\r"
  56. #define DEFAULT_FONT    "^IS%05.5d^-"
  57. #define DELETE_FONTS    "^DFEA^G^-"
  58. #define CLEAR_OVERLAYS    "^DOC^Z^-"
  59. #define SYNTAX        "^ISYNTAX%1.1d%1.1d%1.1d%1.1d%1.1d^-"
  60. #define PORTRAIT    "^IOP^-"
  61. #define LANDSCAPE    "^IOL^-"
  62. #define V_MARGINS    "^IMV%04.4d%04.4d^-"
  63. #define H_MARGINS    "^IMH%04.4d%04.4d^-"
  64. #define CHAR_SP        "^IC%04.4d^-"
  65. #define LINE_SP        "^IL%04.4d^-"
  66.  
  67. hard_init()
  68. {
  69.   fprintf(dev_out,QUIC_ON);        /* Turn on QUIC */
  70.   fprintf(dev_out,DELETE_FONTS);    /* Delete all downloaded fonts */
  71.   fprintf(dev_out,CLEAR_OVERLAYS);    /* Clear all overlays */
  72.   fprintf(dev_out,DEFAULT_FONT,10);    /* Select the font I like */
  73.   soft_init();
  74. }
  75.  
  76. soft_init()
  77. {
  78.   fprintf(dev_out,QUIC_ON);        /* Turn on QUIC */
  79.   fprintf(dev_out,SYNTAX,0,0,0,1,0);    /* Ensure correct SYNTAX */
  80.   if (dev_options & DEV_INIT_LANDSCAPE) {
  81.     fprintf(dev_out,LANDSCAPE);        /* Landscape page orientation */
  82.     fprintf(dev_out,V_MARGINS,0,2550);    /* Vertical margins */
  83.     fprintf(dev_out,H_MARGINS,0,4200);    /* Horizontal margins */
  84.   } else {
  85.     fprintf(dev_out,PORTRAIT);        /* Portrait page orientation */
  86.     fprintf(dev_out,V_MARGINS,0,4200);    /* Vertical margins */
  87.     fprintf(dev_out,H_MARGINS,0,2550);    /* Horizontal margins */
  88.   }
  89.   fprintf(dev_out,CHAR_SP,0);        /* Turn off char spacing */
  90.   fprintf(dev_out,LINE_SP,0);        /* Turn off line spacing */
  91.   page_init();
  92. }
  93.  
  94. page_init()
  95. {
  96.   fprintf(dev_out,"^IH%04.4d^IV%04.4d",DEV_XOFFSET,DEV_YOFFSET);
  97.   dev_h = dev_v = 0;
  98. }     
  99.  
  100. dev_init(f,options,dpi)
  101.      FILE *f;
  102.      unsigned long options;
  103.      long *dpi;
  104. {
  105.   dev_out = f;
  106.   *dpi = DEV_DPI;
  107.   dev_options = options;
  108.   hard_init();
  109. }
  110.  
  111. dev_term()
  112. {
  113.   fprintf(dev_out,QUIC_OFF);
  114.   fflush(dev_out);
  115. }
  116.  
  117.  
  118. dev_print_log(f)
  119.      FILE *f;
  120. {
  121.   register int ch;
  122.  
  123.   if (dev_h || dev_v) putc('\f',dev_out);
  124.   fprintf(dev_out,V_MARGINS,100,3300);    /* Vertical margins */
  125.   fprintf(dev_out,H_MARGINS,100,2550);    /* Horizontal margins */
  126.   fprintf(dev_out,DEFAULT_FONT,10);    /* Select the font I like */
  127.   fprintf(dev_out,"^IH%04.4d^IV%04.4d",100,100);
  128.   fprintf(dev_out,QUIC_OFF);
  129.   while (!ferror(f) && (ch = getc(f)) != EOF) {
  130.     if (ch == '\n') putc('\r',dev_out);
  131.     if (ch == '^') putc(ch,dev_out);
  132.     putc(ch,dev_out);
  133.   }
  134.   putc('\f',dev_out);
  135.   fflush(dev_out);
  136.   fprintf(dev_out,QUIC_ON);
  137. }
  138.  
  139. dev_special(nchars,f)
  140.      int nchars;
  141.      FILE *f;
  142. {
  143.   while (nchars-- > 0) putc(getc(f),dev_out);
  144.   soft_init();
  145. }
  146.